//
//  CrazyChatDataModel.m
//  webSocket
//
//  Created by 马军凯 on 2019/1/18.
//  Copyright © 2019年 ZH. All rights reserved.
//

#import "CrazyChatDataModel.h"

@implementation CrazyChatDataModel

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}




//赋值
- (void)setHistoryValues:(NSDictionary *)dic tableView:(UITableView *)tableView {
    //ID
    self.ID = [NSString stringWithFormat:@"%@", dic[@"id"]];
    NSDictionary *messageDict = dic[@"message"];
    //消息ID
    self.MESSAGE_ID = [NSString stringWithFormat:@"%@", messageDict[@"MESSAGE_ID"]];
    //消息类型
    self.MESSAGE_TYPE = [NSString stringWithFormat:@"%@", messageDict[@"MESSAGE_TYPE"]];
    //消息内容
    if ([self.MESSAGE_TYPE isEqualToString:@"ORDER"]) {
        self.MESSAGE_DATA = [NSString stringWithFormat:@"%@", messageDict[@"MESSAGE_DATA"][@"ORDER_ID"]];
        self.GOODS_ID = [NSString stringWithFormat:@"%@", messageDict[@"MESSAGE_DATA"][@"GOODS_ID"]];
    } else {
        self.MESSAGE_DATA = [NSString stringWithFormat:@"%@", messageDict[@"MESSAGE_DATA"]];
    }
    //来自于哪里
    self.FORM_TYPE = [NSString stringWithFormat:@"%@", dic[@"type"]];
    //是否需要重发 repeatType @"0" 没有重发  @"1" 有重发
    self.repeatType = @"0";
    //时间
    self.VOICE_TIME = [NSString stringWithFormat:@"%@", messageDict[@"VOICE_TIME"]];
    //播放
    self.isPlayVoice = NO;
    //获取商品信息
    if ([self.MESSAGE_TYPE isEqualToString:@"GOODS"]) {
        CrazyWeakSelf;
        NSString *urlString = [CRAZY_CHAT_API_DOMIN stringByAppendingString:@"customer/getGoodsInfo"];
        NSDictionary *params = @{@"goods_id" : weakSelf.MESSAGE_DATA};
        [CrazyNetWork CrazyRequest_Post:urlString HUD:NO parameters:params success:^(NSDictionary *dic, NSString *url, NSString *Json) {
            if ([[NSString stringWithFormat:@"%@",dic[@"code"]] isEqualToString:@"0"]) {
                NSDictionary *dataDict = dic[@"data"];
                weakSelf.GOODSURL = [NSString stringWithFormat:@"%@", dataDict[@"file"]];
                weakSelf.GOODSTITLE = [NSString stringWithFormat:@"%@", dataDict[@"goods_name"]];
                weakSelf.GOODSPRICE = [NSString stringWithFormat:@"%@", dataDict[@"price"]];
            }
            [tableView reloadData];
        } fail:^(NSError *error, NSString *url) {
        }];
    } else if ([self.MESSAGE_TYPE isEqualToString:@"ORDER"]) {
        CrazyWeakSelf;
        NSString *urlString = [CRAZY_CHAT_API_DOMIN stringByAppendingString:@"customer/getOrderInfo"];
        NSDictionary *params = @{@"order_id" : self.MESSAGE_DATA, @"goods_id" : self.GOODS_ID};
        [CrazyNetWork CrazyRequest_Post:urlString HUD:YES parameters:params success:^(NSDictionary *dic, NSString *url, NSString *Json) {
            if ([[NSString stringWithFormat:@"%@",dic[@"code"]] isEqualToString:@"0"]) {
                NSDictionary *dataDict = dic[@"data"];
                weakSelf.GOODSURL = [NSString stringWithFormat:@"%@", dataDict[@"file"]];
                weakSelf.GOODSTITLE = [NSString stringWithFormat:@"%@", dataDict[@"goods_name"]];
                weakSelf.GOODSPRICE = [NSString stringWithFormat:@"%@", dataDict[@"single_price"]];
                weakSelf.GOODSATTR = [NSString stringWithFormat:@"%@", dataDict[@"attr"]];
                weakSelf.GOODSNUM = [NSString stringWithFormat:@"%@", dataDict[@"quantity"]];
                weakSelf.ORDER_STATUS = [NSString stringWithFormat:@"%@", dataDict[@"status"]];
            }
            [tableView reloadData];
        } fail:^(NSError *error, NSString *url) {
            
        }];
    }
}

//赋值
- (void)setCustomSendMessage:(NSDictionary *)dic tableView:(UITableView *)tableView {
    self.MESSAGE_DATA = dic[@"MESSAGE_DATA"];
    self.GOODS_ID = dic[@"GOODS_ID"];
    self.FORM_TYPE = dic[@"FORM_TYPE"];
    self.MESSAGE_ID = dic[@"MESSAGE_ID"];
    self.MESSAGE_TYPE = dic[@"MESSAGE_TYPE"];
    //播放
    self.isPlayVoice = NO;
    //重发
    self.repeatType = @"0";
    //获取商品信息
    if ([self.MESSAGE_TYPE isEqualToString:@"GOODS"]) {
        CrazyWeakSelf;
        NSString *urlString = [CRAZY_CHAT_API_DOMIN stringByAppendingString:@"customer/getGoodsInfo"];
        NSDictionary *params = @{@"goods_id" : self.MESSAGE_DATA};
        [CrazyNetWork CrazyRequest_Post:urlString HUD:NO parameters:params success:^(NSDictionary *dic, NSString *url, NSString *Json) {
            if ([[NSString stringWithFormat:@"%@",dic[@"code"]] isEqualToString:@"0"]) {
                NSDictionary *dataDict = dic[@"data"];
                weakSelf.GOODSURL = [NSString stringWithFormat:@"%@", dataDict[@"file"]];
                weakSelf.GOODSTITLE = [NSString stringWithFormat:@"%@", dataDict[@"goods_name"]];
                weakSelf.GOODSPRICE = [NSString stringWithFormat:@"%@", dataDict[@"price"]];
            }
            [tableView reloadData];
        } fail:^(NSError *error, NSString *url) {
        }];
    } else if ([self.MESSAGE_TYPE isEqualToString:@"ORDER"]) {
        CrazyWeakSelf;
        NSString *urlString = [CRAZY_CHAT_API_DOMIN stringByAppendingString:@"customer/getOrderInfo"];
        NSDictionary *params = @{@"order_id" : self.MESSAGE_DATA, @"goods_id" : self.GOODS_ID};
        [CrazyNetWork CrazyRequest_Post:urlString HUD:YES parameters:params success:^(NSDictionary *dic, NSString *url, NSString *Json) {
            if ([[NSString stringWithFormat:@"%@",dic[@"code"]] isEqualToString:@"0"]) {
                NSDictionary *dataDict = dic[@"data"];
                weakSelf.GOODSURL = [NSString stringWithFormat:@"%@", dataDict[@"file"]];
                weakSelf.GOODSTITLE = [NSString stringWithFormat:@"%@", dataDict[@"goods_name"]];
                weakSelf.GOODSPRICE = [NSString stringWithFormat:@"%@", dataDict[@"single_price"]];
                weakSelf.GOODSATTR = [NSString stringWithFormat:@"%@", dataDict[@"attr"]];
                weakSelf.GOODSNUM = [NSString stringWithFormat:@"%@", dataDict[@"quantity"]];
                weakSelf.ORDER_STATUS = [NSString stringWithFormat:@"%@", dataDict[@"status"]];
            }
            [tableView reloadData];
        } fail:^(NSError *error, NSString *url) {
            
        }];
    }
}

@end














